export const createListSlice = (set:any, ...rest:any) => ({

  todoList: [
    { title: 'demo1', due: '2023-5-5', isDone: false },
    { title: 'demo2', due: '2023-5-7', isDone: false },
    { title: 'demo3', due: '2023-5-9', isDone: false },
  ],
  todoItem: { title: '', due: null },
  setTitle: (title:string) => set((state:any) => {
    const todoItem = state.todoItem
    todoItem.title = title
    return {
      todoItem: { ...todoItem }
    }
  }),
  setDueDate: (due:string) => set((state:any) => {
    const todoItem = state.todoItem
    todoItem.due = due
    return {
      todoItem: { ...todoItem }
    }
  }),
  pushItem2List: () => set((state:any) => {
    const todoList = state.todoList
    todoList.push({ ...state.todoItem, isDone: false })
    return {
      todoItem: { title: '', due: null },
      todoList: [ ...todoList ]
    }
  }),
  removeItemFromList: (id: number) => set((state:any) => {
    state.todoList.splice(id, 1)
    const todoList = [...state.todoList]
    return {
      todoList
    }
  }),
  setItemCheck: (id: number, checked: boolean) => set((state:any) => {
    state.todoList[id].isDone = checked
    const todoList = [...state.todoList]
    return {
      todoList
    }
  })
})
